<template></template>

<!-- <template>
    <view>
        <collapse v-if="showLoginBtn" title="微信授权提醒" header-class="collapse__header">
            <view class="ui-card">
                <view class="font-gray-28">点击按钮授权后……</view>
                <button class="weui-btn" open-type="getUserInfo" @getuserinfo="onClickLoginBtn">上传我的头像与昵称</button>
            </view>
        </collapse>
        <view class="weui-cells">
            <navigator url="./children/personal-information" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
                <view class="weui-cell__hd">
                    <view class="user-info__avatar">
                        <open-data type="userAvatarUrl"></open-data>
                    </view>
                </view>
                <view class="weui-cell__bd">
                    <view class="user-info__name">
                        <open-data type="userNickName"></open-data>
                    </view>
                    <view class="font-gray-28">查看 / 修改个人信息</view>
                </view>
                <view class="weui-cell__ft weui-cell__ft_in-access"></view>
            </navigator>
        </view>
        <view class="weui-cells">
            <navigator url="./children/qrcode" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
                <view class="weui-cell__hd">
                    <image src="/static/images/icon_paper_plane.png" class="icon"></image>
                </view>
                <view class="weui-cell__bd">我的二维码</view>
                <view class="weui-cell__ft weui-cell__ft_in-access"></view>
            </navigator>
        </view>
        </view>
        <view class="weui-cells">
 
            <navigator url="./children/about" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
                <view class="weui-cell__hd">
                    <image src="/static/images/icon_info.png" class="icon"></image>
                </view>
                <view class="weui-cell__bd">关于</view>
                <view class="weui-cell__ft weui-cell__ft_in-access"></view>
            </navigator>
        </view>
        <view class="weui-cells">
            <view class="weui-cell weui-cell_access" hover-class="weui-cell_active">
                <view class="weui-cell__hd">
                    <image src="/static/images/icon_logout.png" class="icon"></image>
                </view>
                <view class="weui-cell__bd" @tap="onLogout">退出登录</view>
                <view class="weui-cell__ft weui-cell__ft_in-access"></view>
            </view>
        </view>
    </view>
</template>

<script>
import collapse from '@/components/collapse/index';
import Promisify from '../../utils/promisify';
import { updateUserInfoById } from '../../apis/user';
import { logout, getUID } from '../../utils/permission';
var app = getApp();
export default {
    components: {
        collapse
    },
    data() {
        return {
            showLoginBtn: false
        };
    },
    onLoad: function () {
        // 获取用户授权，更新用户昵称与头像
        Promisify(uni.getUserInfo)()
            .then(this._updateUserInfo)
            .catch(() =>
                this.setData({
                    showLoginBtn: true
                })
            );
    },
    methods: {
        onLogout: function () {
            uni.showModal({
                content: '确定退出登录？',
                success: (res) => {
                    if (res.confirm && logout()) {
                        uni.reLaunch({
                            url: '/pages/register/register'
                        });
                    }
                }
            });
        },

        onClickLoginBtn: function (e) {
            let { errMsg } = e.detail;
            if (errMsg.indexOf('fail') === -1) {
                this.updateUserInfoFun(e.detail).then(() => {
                    this.setData({
                        showLoginBtn: false
                    });
                });
                uni.showToast({
                    title: '授权成功'
                });
            }
        },

        updateUserInfoFun: function (userInfo) {
            return updateUserInfoById(getUID(), {
                nickname: userInfo.userInfo.nickName,
                avatar: userInfo.userInfo.avatarUrl
            }).then((res) => app.globalData.setUserInfo(res));
        }
    }
};
</script>
<style>
page {
    padding-bottom: 20px;
}

.collapse__header {
    background-color: #ffbf00 !important;
    color: #fff !important;
    border-top: none !important;
}

collapse .ui-card {
    padding: 15px;
}
collapse .ui-card:before {
    display: none;
}

.icon {
    margin-right: 5px;
    vertical-align: middle;
    width: 20px;
    height: 20px;
}

.user-info__avatar {
    width: 64px;
    height: 64px;
    margin-right: 15px;
    vertical-align: middle;
    border-radius: 32px;
    overflow: hidden;
}

.user-info__name {
    margin-bottom: 12rpx;
}
</style> -->
